package com.jx.gocomtask.webservice.restcontroller;

import com.jx.gocomtask.utils.JaxbUtil;
import com.jx.gocomtask.webservice.DTO.GroupPostMessage;
import com.jx.gocomtask.webservice.service.Route;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@ApiIgnore
@RestController
@RequestMapping("/groupbot")
public class MessageCallback {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MessageCallback.class);
	@Autowired
	Route route;

	@RequestMapping(value = "/callback", method = RequestMethod.POST)
	@ResponseStatus(HttpStatus.OK)
	public Object group_bots(HttpServletRequest request) throws IOException {
			StringBuffer sb=new StringBuffer();
			request.getReader().lines().forEach(line -> sb.append(line));
			String str=sb.toString();
			if(str==null || str.isEmpty() ){
				return null;
			}
			GroupPostMessage postMessage = JaxbUtil.converyToJavaBean(str, GroupPostMessage.class);
			if(postMessage==null){
				return null;
			}
			route.messageHandle(postMessage);
		return null;
	}
}
